package com.woniuxy.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.woniuxy.entity.DisRequirements;
import com.woniuxy.entity.Procurement;
import com.woniuxy.service.DisRequirementsService;
import com.woniuxy.utils.Result;

@Controller
@RequestMapping("/disRequirements")
public class DisRequirementsController {
	@Autowired
	private DisRequirementsService disRequirementsService;
	
	@RequiresPermissions("manager:find")
	@RequestMapping("/findRequirements")
	@ResponseBody
	public List<DisRequirements> findRequirements(){
		return disRequirementsService.findRequirements();
	}
	
	@RequiresPermissions("manager:find")
	@RequestMapping("/finddisRequirementByOrderno")
	@ResponseBody
	public DisRequirements finddisRequirementByOrderno(String orderno){
		return disRequirementsService.finddisRequirementByOrderno(orderno);
	}
	
	@RequiresPermissions("manager:add")
	@RequestMapping("/insert")
	@ResponseBody
	public Result<String> insertDisprocurement(DisRequirements dis){
		Result<String> result=new Result<>();
		int i=disRequirementsService.insertDisprocurement(dis);
		if (i!=0) {
			result.setMessage("插入数据成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:update")
	@RequestMapping("/update")
	@ResponseBody
	public Result<String> updatedistributionByOrderno(DisRequirements dis){
		Result<String> result=new Result<>();
		int i=disRequirementsService.updatedistributionByOrderno(dis);
		if (i!=0) {
			result.setMessage("编辑数据成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:del")
	@RequestMapping("/delDisByOrderno")
	@ResponseBody
	public Result<String> delDisByOrderno(String orderno){
		Result<String> result=new Result<>();
		int i=disRequirementsService.delDisByOrderno(orderno);
		if (i!=0) {
			result.setMessage("删除成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:add")
	@RequestMapping("/insertToProcurement")
	@ResponseBody
	public Result<String> insertToProcurement(Procurement procurement){
		Result<String> result=new Result<>();
		int i=disRequirementsService.insertToProcurement(procurement);
		if (i!=0) {
			result.setMessage("提交采购成功");
		}
		return result;
	}
	
	@RequiresPermissions("manager:update")
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Result<String> changeStatus(DisRequirements disRequirements){
		Result<String> result=new Result<>();
		int i=disRequirementsService.changeStatus(disRequirements);
		if (i!=0) {
			result.setMessage("修改状态成功");
		}
		return result;
	}
}
